<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('选择设备')" />
	<th:block th:include="include :: bootstrap-fileinput-css"/>
</head>

<body class="gray-bg">
	<input id="aid"   name="aid"    type="hidden"  value = ""/>
	<input id="aassetsName"   name="aassetsName"    type="hidden" value=""/>
	<input id="aassetsType"   name="aassetsType"    type="hidden" value=""/>
	<input id="aassetsModel"   name="aassetsModel"    type="hidden" value=""/>
	<input id="aassetsSn"   name="aassetsSn"    type="hidden" value=""/>
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="role-form">
					<div class="select-list">
						<ul>
							<li>
								<label>资产名称：</label>
								<input type="text" name="assetsName"/>
							</li>
							<li>
								<label>资产类别：</label>
								<select name="assetsType" th:with="type=${@dict.getType('assets_type')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li>
							<li>
								<label>规格型号：</label>
								<input type="text" name="assetsModel"/>
							</li>
							<li>
								<label>SN号：</label>
								<input type="text" name="assetsSn"/>
								<input name="assetsStatus" th:value="${status}" type="hidden"/>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var datas = [[${@dict.getType('sys_normal_disable')}]];
		var prefix = ctx + "assets/assets";
		var assetsTypeDatas = [[${@dict.getType('assets_type')}]];
		$(function() {
			var options = {
		        url: prefix + "/list",
		        queryParams: queryParams,
		        sortName: "createTime",
		        sortOrder: "desc",
		        showToggle: false,
		        showColumns: false,
		        clickToSelect: true,
		        rememberSelected: true,
				singleSelect: true,
				onCheck:selectUser,
				columns: [{
					checkbox: true
				},
					{
						field: 'id',
						title: '资产编号',
						visible: false
					},
					{
						field: 'assetsName',
						title: '资产名称'
					},
					{
						field: 'assetsType',
						title: '资产类别',
						formatter: function(value, row, index) {
							return $.table.selectDictLabel(assetsTypeDatas, value);
						}
					},
					{
						field: 'assetsModel',
						title: '规格型号'
					},
					{
						field: 'assetsSn',
						title: 'SN号'
					},{
						field: 'assetsBuytime',
						title: '购入日期'
					},
					{
						field: 'createTime',
						title: '入库日期'
					}]
		    };
		    $.table.init(options);
		});
		
		function queryParams(params) {
			var search = $.table.queryParams(params);
			return search;
		}
		
		/* 添加用户-选择资产 */
		function selectUser() {
			var rows = $.table.selectFirstColumns();
			if (rows.length == 0) {
       			$.modal.alertWarning("请至少选择一条记录");
       			return;
       		}
			if (rows.length > 1) {
				$.modal.alertWarning("只能选择一条记录");
				return;
			}

			var aid = $.table.selectColumns('id');
			var aassetsName = $.table.selectColumns('assetsName');
			var aassetsType = $.table.selectColumns('assetsType');
			var aassetsModel = $.table.selectColumns('assetsModel');
			var aassetsSn = $.table.selectColumns('assetsSn');

			$("*[name='aid']").val(aid);
			$("*[name='aassetsName']").val(aassetsName);
			$("*[name='aassetsType']").val(aassetsType);
			$("*[name='aassetsModel']").val(aassetsModel);
			$("*[name='aassetsSn']").val(aassetsSn);

		}
	</script>
</body>
</html>